﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Caching;

namespace NWebMock
{
    public interface IHttpResponse
    {
        #region Properties

        /// <summary>
        /// Gets or sets a value indicating whether to buffer output and send it after the complete response is finished processing.
        /// </summary>
        bool Buffer { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to buffer output and send it after the complete page is finished processing.
        /// </summary>
        bool BufferOutput { get; set; }

        /// <summary>
        /// Gets the caching policy (such as expiration time, privacy settings, and vary clauses) of a Web page.
        /// </summary>
        IHttpCachePolicy Cache { get; }

        /// <summary>
        /// Gets or sets the Cache-Control HTTP header that matches one of the HttpCacheability enumeration values.
        /// </summary>
        string CacheControl { get; set; }

        /// <summary>
        /// Gets or sets the HTTP character set of the output stream.
        /// </summary>
        string Charset { get; set; }

        /// <summary>
        /// Gets or sets the HTTP character set of the output stream.
        /// </summary>
        Encoding ContentEncoding { get; set; }

        /// <summary>
        /// Gets or sets the HTTP MIME type of the output stream.
        /// </summary>
        string ContentType { get; set; }

        /// <summary>
        /// Gets the response cookie collection.
        /// </summary>
        IHttpCookieCollection Cookies { get; }

        /// <summary>
        /// Gets or sets the number of minutes before a page cached on a browser expires. If the user returns to the same page before it expires, the cached version is displayed. Expires is provided for compatibility with earlier versions of ASP.
        /// </summary>
        int Expires { get; set; }

        /// <summary>
        /// Gets or sets the absolute date and time at which to remove cached information from the cache. ExpiresAbsolute is provided for compatibility with earlier versions of ASP.
        /// </summary>
        DateTime ExpiresAbsolute { get; set; }

        /// <summary>
        /// Gets or sets a wrapping filter object that is used to modify the HTTP entity body before transmission.
        /// </summary>
        Stream Filter { get; set; }

        /// <summary>
        /// Gets or sets an Encoding object that represents the encoding for the current header output stream.
        /// </summary>
        Encoding HeaderEncoding { get; set; }

        /// <summary>
        /// Gets the collection of response headers.
        /// </summary>
        NameValueCollection Headers { get; }

        /// <summary>
        /// Gets a value indicating whether the client is still connected to the server.
        /// </summary>
        bool IsClientConnected { get; }

        /// <summary>
        /// Gets a Boolean value indicating whether the client is being transferred to a new location.
        /// </summary>
        bool IsRequestBeingRedirected { get; }

        /// <summary>
        /// Enables output of text to the outgoing HTTP response stream.
        /// </summary>
        TextWriter Output { get; }

        /// <summary>
        /// Enables binary output to the outgoing HTTP content body.
        /// </summary>
        Stream OutputStream { get; }

        /// <summary>
        /// Gets or sets the value of the Http Location header.
        /// </summary>
        string RedirectLocation { get; set; }

        /// <summary>
        /// Sets the Status line that is returned to the client.
        /// </summary>
        string Status { get; set; }

        /// <summary>
        /// Gets or sets the HTTP status code of the output returned to the client.
        /// </summary>
        int StatusCode { get; set; }

        /// <summary>
        /// Gets or sets the HTTP status string of the output returned to the client.
        /// </summary>
        string StatusDescription { get; set; }

        /// <summary>
        /// Gets or sets a value qualifying the status code of the response.
        /// </summary>
        int SubStatusCode { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to send HTTP content to the client.
        /// </summary>
        bool SuppressContent { get; set; }

        /// <summary>
        /// Gets or sets a value that specifies whether IIS 7.0 custom errors are disabled.
        /// </summary>
        bool TrySkipIisCustomErrors { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// Associates a set of cache dependencies with the response to facilitate invalidation of the response if it is stored in the output cache and the specified dependencies change.
        /// </summary>
        /// <param name="dependencies">A file, cache key, or CacheDependency to add to the list of application dependencies.</param>
        void AddCacheDependency(params CacheDependency[] dependencies);

        /// <summary>
        /// Makes the validity of a cached response dependent on other items in the cache.
        /// </summary>
        /// <param name="cacheKeys">The ArrayList that contains the keys of the items that the current cached response is dependent upon.</param>
        void AddCacheItemDependencies(ArrayList cacheKeys);

        /// <summary>
        /// Makes the validity of a cached item dependent on another item in the cache.
        /// </summary>
        /// <param name="cacheKeys">An array of item keys that the cached response is dependent upon.</param>
        void AddCacheItemDependencies(string[] cacheKeys);

        /// <summary>
        /// Makes the validity of a cached response dependent on another item in the cache.
        /// </summary>
        /// <param name="cacheKey">The key of the item that the cached response is dependent upon.</param>
        void AddCacheItemDependency(string cacheKey);

        /// <summary>
        /// Adds a group of file names to the collection of file names on which the current response is dependent.
        /// </summary>
        /// <param name="filenames">The collection of files to add.</param>
        void AddFileDependencies(ArrayList filenames);

        /// <summary>
        /// Adds an array of file names to the collection of file names on which the current response is dependent.
        /// </summary>
        /// <param name="filenames">An array of files to add.</param>
        void AddFileDependencies(string[] filenames);

        /// <summary>
        /// Adds a single file name to the collection of file names on which the current response is dependent.
        /// </summary>
        /// <param name="filename">The name of the file to add.</param>
        void AddFileDependency(string filename);

        /// <summary>
        /// Adds an HTTP header to the output stream. AddHeader is provided for compatibility with earlier versions of ASP.
        /// </summary>
        /// <param name="name">The name of the HTTP header to add value to.</param>
        /// <param name="value">The string to add to the header.</param>
        void AddHeader(string name, string value);

        /// <summary>
        /// Adds an HTTP header to the output stream.
        /// </summary>
        /// <param name="name">The name of the HTTP header to add to the output stream.</param>
        /// <param name="value">The string to append to the header.</param>
        void AppendHeader(string name, string value);

        /// <summary>
        /// Adds custom log information to the Internet Information Services (IIS) log file.
        /// </summary>
        /// <param name="param">The text to add to the log file.</param>
        void AppendToLog(string param);

        /// <summary>
        /// Adds a session ID to the virtual path if the session is using Cookieless session state and returns the combined path. If Cookieless session state is not used, ApplyAppPathModifier returns the original virtual path.
        /// </summary>
        /// <param name="virtualPath">The virtual path to a resource.</param>
        /// <returns>The virtualPath with the session ID inserted.</returns>
        string ApplyAppPathModifier(string virtualPath);

        /// <summary>
        /// Writes a string of binary characters to the HTTP output stream.
        /// </summary>
        /// <param name="buffer">The bytes to write to the output stream.</param>
        void BinaryWrite(byte[] buffer);

        /// <summary>
        /// Clears all content output from the buffer stream.
        /// </summary>
        void Clear();

        /// <summary>
        /// Clears all content output from the buffer stream.
        /// </summary>
        void ClearContent();

        /// <summary>
        /// Clears all headers from the buffer stream.
        /// </summary>
        void ClearHeaders();

        /// <summary>
        /// Closes the socket connection to a client.
        /// </summary>
        void Close();

        /// <summary>
        /// Disables kernel caching for the current response.
        /// </summary>
        void DisableKernelCache();

        /// <summary>
        /// Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.
        /// </summary>
        void End();

        /// <summary>
        /// Sends all currently buffered output to the client.
        /// </summary>
        void Flush();

        /// <summary>
        /// Appends a HTTP PICS-Label header to the output stream.
        /// </summary>
        /// <param name="value">The string to add to the PICS-Label header.</param>
        void Pics(string value);

        /// <summary>
        /// Redirects a client to a new URL and specifies the new URL.
        /// </summary>
        /// <param name="url">The target location.</param>
        void Redirect(string url);

        /// <summary>
        /// Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
        /// </summary>
        /// <param name="url">The location of the target.</param>
        /// <param name="endResponse">Indicates whether execution of the current page should terminate.</param>
        void Redirect(string url, bool endResponse);

        /// <summary>
        /// Writes the specified file directly to an HTTP response output stream, without buffering it in memory.
        /// </summary>
        /// <param name="filename">The name of the file to write to the HTTP output.</param>
        void TransmitFile(string filename);

        /// <summary>
        /// Writes the specified part of a file directly to an HTTP response output stream without buffering it in memory.
        /// </summary>
        /// <param name="filename">The name of the file to write to the HTTP output.</param>
        /// <param name="offset">The position in the file to begin to write to the HTTP output.</param>
        /// <param name="length">The number of bytes to be transmitted.</param>
        void TransmitFile(string filename, long offset, long length);

        /// <summary>
        /// Writes a character to an HTTP response output stream.
        /// </summary>
        /// <param name="ch">The character to write to the HTTP output stream.</param>
        void Write(char ch);

        /// <summary>
        /// Writes an Object to an HTTP response stream.
        /// </summary>
        /// <param name="obj">The Object to write to the HTTP output stream.</param>
        void Write(Object obj);

        /// <summary>
        /// Writes a string to an HTTP response output stream.
        /// </summary>
        /// <param name="s">The string to write to the HTTP output stream.</param>
        void Write(string s);

        /// <summary>
        /// Writes an array of characters to an HTTP response output stream.
        /// </summary>
        /// <param name="buffer">The character array to write.</param>
        /// <param name="index">The position in the character array where writing starts.</param>
        /// <param name="count">The number of characters to write, beginning at index.</param>
        void Write(char[] buffer, int index, int count);

        /// <summary>
        /// Writes the contents of the specified file directly to an HTTP response output stream as a file block.
        /// </summary>
        /// <param name="filename">The name of the file to write to the HTTP output.</param>
        void WriteFile(string filename);

        /// <summary>
        /// Writes the contents of the specified file directly to an HTTP response output stream as a memory block.
        /// </summary>
        /// <param name="filename">The name of the file to write into a memory block.</param>
        /// <param name="readIntoMemory">Indicates whether the file will be written into a memory block.</param>
        void WriteFile(string filename, bool readIntoMemory);

        /// <summary>
        /// Writes the specified file directly to an HTTP response output stream.
        /// </summary>
        /// <param name="fileHandle">The file handle of the file to write to the HTTP output stream.</param>
        /// <param name="offset">The byte position in the file where writing will start.</param>
        /// <param name="size">The number of bytes to write to the output stream.</param>
        void WriteFile(IntPtr fileHandle, long offset, long size);

        /// <summary>
        /// Writes the specified file directly to an HTTP response output stream.
        /// </summary>
        /// <param name="filename">The name of the file to write to the HTTP output stream.</param>
        /// <param name="offset">The byte position in the file where writing will start.</param>
        /// <param name="size">The number of bytes to write to the output stream.</param>
        void WriteFile(string filename, long offset, long size);

        /// <summary>
        /// Allows insertion of response substitution blocks into the response, which allows dynamic generation of specified response regions for output cached responses.
        /// </summary>
        /// <param name="callback">The method, user control, or object to substitute.</param>
        void WriteSubstitution(HttpResponseSubstitutionCallback callback);

        #endregion
    }
}
